import React, {useEffect, useState} from 'react'
import {Button, Modal, Table} from 'antd'
import { connect } from 'umi'
import moment from 'moment';
import { distributionStatusList, BPMStatusEnum } from '@/utils/constant'
import { getAwardApplicantById } from '../../service'
import {formatNumber} from "@/utils/utils";

const Details = (props) => {

  const { visible,onCancel,id,reanpu} = props;
  const [data, setData] = useState([]);

  useEffect(() => {
    if(id){
      getAwardApplicantById(id).then(res => {
        setData(res);
      });
    }
  }, [visible]);

  const onFormCancel = () =>{
    setData([]);
    onCancel();
  };

  const columns = [
    {
      title: '序号',
      render:(text,record,index)=>`${index+1}`,
      hideInSearch: true,
    },
    {
      title: '申请日期',
      dataIndex: 'applyTime',
      hideInSearch: true,
      render: (text) => {
        return text != '-' ? moment(text).format('YYYY-MM-DD') : '';
      },
    },
    {
      title: '申请人',
      dataIndex: 'applicantName',
    },
    {
      title: '申请人公司',
      dataIndex: 'orgname',
      hideInSearch: true,
    },
    {
      title: '申请人部门',
      dataIndex: 'department',
      hideInSearch: true,
    },
    {
      title: '奖罚名称',
      dataIndex: 'awardName',
    },
    {
      title: '奖罚种类',
      dataIndex: 'type',
      hideInSearch: true,
      render: (text) => {
        const res = reanpu.find((item) => item.code === text);
        return res ? res.name : text;
      }
    },
    {
      title: '总金额',
      dataIndex: 'distributionAmount',
      hideInSearch: true,
      render:(text) =>{
        return formatNumber(text)
      },
    },
    {
      title: '分配状态',
      dataIndex: 'distributionStatus',
      hideInSearch: true,
      render:(text) =>{
        return distributionStatusList.find((item) => item.value === parseInt(text))?.label;
      },
    },
  ];

  return (
    <Modal
      width={'70%'}
      title="分配详情"
      visible={visible}
      footer={<Button type="primary" onClick={() => onFormCancel()}>返回</Button>}
      onCancel={() => onFormCancel()}
    >
      <Table
        rowKey="id"
        columns={columns}
        dataSource={data}
        pagination={false}
      />
    </Modal>
  )
};

export default connect(() => ({
}))(Details)
